<template>
  <div class="app-container">
    <Search-content :queryParams="queryParams" labelWidth="120px" @query="handleQuery" @reset="resetQuery">
      <el-col :span="6">
        <el-form-item label="车牌号:">
          <el-input v-model="queryParams.carNo" clearable placeholder="请输入车牌号"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车架号:">
          <el-input v-model="queryParams.vinNo" clearable placeholder="请输入车架号"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="品牌/车系/车型:">
          <linkage-select @changeNode="linkageChange" v-model="linkageList" placeholder="请选择品牌/车系/车型"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="牌照性质:">
          <el-input v-model="queryParams.licenseNature" clearable placeholder="请输入牌照性质"/>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="排放标准:">
          <el-input v-model="queryParams.environmentalStandards" clearable placeholder="请输入排放标准"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车况等级:">
          <el-select v-model="queryParams.vehicleConditionLevel" placeholder="请选择预警状态" clearable>
            <el-option v-for="dict in dict.type.vehicle_condition_level_type" :key="dict.value" :label="dict.label"
                       :value="dict.value"/>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车辆产权:">
          <el-input v-model="queryParams.propertyRightName" clearable placeholder="请输入牌照性质"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="申请人:">
          <el-input v-model="queryParams.proposer" clearable placeholder="请输入申请人"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="申请时间:">
          <el-date-picker v-model="valueDate" type="daterange" placeholder="请选择日期" range-separator="-"
                          start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="预警状态:">
          <el-select v-model="queryParams.warningState" placeholder="请选择预警状态" clearable>
            <el-option v-for="dict in dict.type.warning_state_type" :key="dict.value" :label="dict.label"
                       :value="dict.value"/>
          </el-select>
        </el-form-item>
      </el-col>
    </Search-content>

    <div class="card-wrap card-padding">

      <table-page :loading="loading" :dataList="dataList" :total="total" :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize" @setSizeCurrent="handleList" border>

        <template slot="tableColAc">
          <el-table-column label="操作" align="center" fixed="left" width="230">
            <template #default="{row}">
              <el-button size="mini" type="text" @click="handleView(row, 'view')"
                         v-hasPermi="['routineHandle:routineHandleList:view']">
                查看
              </el-button>

              <el-button size="mini" type="text" @click="handleSubmitResult(row)"
                         v-if="[2,5].includes(Number(row.disposalStatus))"
                         v-hasPermi="['routineHandle:routineHandleList:result']">
                提交处置结果
              </el-button>

              <el-button size="mini" type="text" @click="handleSalvageValue(row)"
                         v-if="[2].includes(Number(row.disposalStatus))"
                         v-hasPermi="['routineHandle:routineHandleList:value']">
                修改残值
              </el-button>

              <el-button size="mini" type="text" @click="handleUploadContract(row)"
                         v-if="[6].includes(Number(row.disposalStatus))"
                         v-hasPermi="['routineHandle:routineHandleList:contract']">
                上传合同
              </el-button>

              <el-button size="mini" type="text" @click="handleUnderwriterDefault(row)"
                         v-if="[6,7,8,9].includes(Number(row.disposalStatus))"
                         v-hasPermi="['routineHandle:routineHandleList:default']">
                承销商违约
              </el-button>

              <el-button size="mini" type="text" @click="handleSubmitPaymentProof(row)"
                         v-if="[7].includes(Number(row.disposalStatus))"
                         v-hasPermi="['routineHandle:routineHandleList:proof']">
                提交付款凭证
              </el-button>

              <el-button size="mini" type="text" @click="handleSubmitProcedure(row)"
                         v-if="[10].includes(Number(row.disposalStatus))"
                         v-hasPermi="['routineHandle:routineHandleList:procedure']">
                提交手续
              </el-button>

            </template>
          </el-table-column>

        </template>

        <template slot="tableCol">
          <el-table-column align="center" label="常规处置编号" min-width="215" show-overflow-tooltip
                           prop="vehicleDisposalNo"/>

          <el-table-column align="center" label="车牌号" min-width="140" show-overflow-tooltip prop="carNo"/>

          <el-table-column align="center" label="初期残值(元)" min-width="120" show-overflow-tooltip
                           prop="initialResidualValue">
            <template #default="{row}">
              {{ format_thousand(row.initialResidualValue) }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="最新残值(元)" min-width="120" show-overflow-tooltip
                           prop="latestResidualValue">
            <template #default="{row}">
              {{ format_thousand(row.latestResidualValue) }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="成交价(元)" min-width="100" show-overflow-tooltip prop="finalPrice">
            <template #default="{row}">
              {{ format_thousand(row.finalPrice) }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="处置状态" min-width="100" show-overflow-tooltip prop="carNo">
            <template #default="{row}">
              {{ selectDictLabel(dict.type.disposal_status_type, row.disposalStatus) }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="车架号" min-width="180" show-overflow-tooltip prop="vinNo"/>

          <el-table-column  label="品牌/车型/车款" show-overflow-tooltip min-width="400">
            <template #default="{row}">
              {{ row.brandName }}{{ row.seriesName }}{{ row.modelName }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="排放标准" show-overflow-tooltip min-width="130"
                           prop="environmentalStandards"/>

          <el-table-column align="center" label="登记日期" show-overflow-tooltip min-width="100"
                           prop="compulsoryAlreadyAmortization">
            <template #default="{row}">
              {{ row.registerTime ? $dayjs(row.registerTime).format('YYYY-MM-DD') : '' }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="预警车龄" show-overflow-tooltip min-width="120"
                           prop="carAge"/>

          <el-table-column align="center" label="车况等级" show-overflow-tooltip min-width="100">
            <template #default="{row}">
              {{ selectDictLabel(dict.type.vehicle_condition_level_type, row.vehicleConditionLevel) }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="车辆产权" show-overflow-tooltip min-width="130"
                           prop="propertyRightName"/>

          <el-table-column align="center" label="申请人" show-overflow-tooltip min-width="120"
                           prop="proposer"/>

          <el-table-column align="center" label="申请时间" show-overflow-tooltip min-width="120">
            <template #default="{row}">
              {{ row.proposerTime ? $dayjs(row.proposerTime).format('YYYY-MM-DD') : '' }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="工单生成时间" show-overflow-tooltip min-width="120">
            <template #default="{row}">
              {{ row.commercialStartTime ? $dayjs(row.commercialStartTime).format('YYYY-MM-DD') : '' }}
            </template>
          </el-table-column>

        </template>
      </table-page>
    </div>
    <!--上传合同-->
    <uploadContractDialog ref="refUploadContractDialog" @successUploadContract="successList"/>
    <!--承销商违约-->
    <underwriterDefault ref="refUnderwriterDefault" @refresh="successList"/>
    <!--提交付款凭证-->
    <paymentDocument ref="refPaymentDocument" @refresh="successList"/>
    <!-- 提交手续-->
    <submitProcedure ref="refSubmitProcedure" @refresh="successList"/>
  </div>
</template>

<script>
import LinkageSelect from "@/views/components/linkageSelect.vue";
import SearchContent from "@/components/SearchContent/index.vue";
import uploadContractDialog from '../../components/routineDisposal/routineHandle/uploadContractDialog.vue'
import underwriterDefault from "../../components/routineDisposal/routineHandle/underwriterDefault.vue";
import paymentDocument from "../../components/routineDisposal/routineHandle/paymentDocument.vue";
import submitProcedure from "../../components/routineDisposal/routineHandle/submitProcedure.vue";
import * as apis from '@/api/vehicleDisposal/routineHandle.js'

export default {
  name: "RoutineHandleList", // 常规处置处理列表
  dicts: ['vehicle_condition_level_type', 'warning_state_type', 'disposal_status_type'],
  components: {
    SearchContent, LinkageSelect,
    uploadContractDialog, underwriterDefault,
    paymentDocument, submitProcedure
  },
  computed: {},
  watch: {},
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carNo: "",
        vinNo: "",
        brandId: "",
        seriesId: "",
        modelId: "",
        licenseNature: "",
        environmentalStandards: "",
        vehicleConditionLevel: "",
        propertyRightName: "",
        proposer: "",
        warningState: "",
      },
      linkageList: [],
      dataList: [
        {
          carNo: "111111",
        },
      ],
      total: 0,
      loading: false,
      valueDate: [],
    };
  },
  created() {
    this.handleList()
  },
  mounted() {
  },
  methods: {
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.handleList();
    },

    resetQuery() {
      this.linkageList = [];
      this.valueDate = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        carNo: "",
        vinNo: "",
        brandId: "",
        seriesId: "",
        modelId: "",
        licenseNature: "",
        environmentalStandards: "",
        vehicleConditionLevel: "",
        propertyRightName: "",
        proposer: "",
        warningState: "",
      };
      this.handleList();
    },

    linkageChange(val) {
      this.linkageList = val;
      if (val) {
        this.queryParams.brandName = val[0] ? val[0].name : "";
        this.queryParams.seriesName = val[1] ? val[1].name : "";
        this.queryParams.modelName = val[2] ? val[2].name : "";
      } else {
        this.queryParams.brandName = "";
        this.queryParams.seriesName = "";
        this.queryParams.modelName = "";
      }
      this.$forceUpdate();
    },

    //列表
    async handleList() {
      this.loading = true;
      try {
        const res = await apis.handleList(this.queryParams);
        this.dataList = res.rows;
        this.total = res.total;
      } catch (e) {
        console.error("获取失败", e);
      } finally {
        this.loading = false;
      }
    },

    //查看
    handleView(row) {
      this._toPage({
        path: "/VehicleDisposal/RoutineDisposal/RoutineHandleDetails",
        name: "RoutineHandleDetails",
        query: {
          type: "view",
          path: 'RoutineHandleList',
          id: row.vehicleDisposalId
        },
      });
    },

    //提交处置结果
    handleSubmitResult(row) {
      this._toPage({
        path: "/VehicleDisposal/RoutineDisposal/SubmitResult",
        name: "SubmitResult",
        query: {
          type: "view",
          id: row.vehicleDisposalId
        },
      });
    },

    //修改残值
    handleSalvageValue(row) {
      this._toPage({
        path: "/VehicleDisposal/RoutineDisposal/EditSalvage",
        name: "EditSalvage",
        query: {
          type: "edit",
          id: row.vehicleDisposalId,
          path:'RoutineHandleList'
        },
      });
    },

    //上传合同
    handleUploadContract(row) {
      this.$refs.refUploadContractDialog.handleOpen(row.vehicleDisposalId)
    },

    //承销商违约
    handleUnderwriterDefault(row) {
      this.$refs.refUnderwriterDefault.handleOpen(row)
    },

    //提交付款凭证
    handleSubmitPaymentProof(row) {
      this.$refs.refPaymentDocument.handleOpen(row)
    },

    //提交手续
    handleSubmitProcedure(row) {
      this.$refs.refSubmitProcedure.handleOpen(row)
    },

    //上传合同成功  承销商违约
    successList() {
      this.queryParams.pageNum = 1;
      this.handleList();
    },
  },
};
</script>

<style scoped lang=""></style>


